<?php
/**
 * 角色设置
 */
apf_require_controller("Abstract");
apf_require_class("Bll_Hr_Property");
class Flow_RoleController extends AbstractController {

    public function handle_request() {
        //检测用户权限
        if(!$this->check_role_auth()){
            $this->show_tips('ERROR_AUTH');
        }
        $role_list = array();
        $params = $this->request->get_parameters();
        $city_id   = $params['city_id'] ? intval($params['city_id']) : 11;
        $role_type = $params['role_type'] ? intval($params['role_type']) : 0;

        $bll_pro = new Bll_Hr_Property();
        $city_list = $bll_pro->get_city_list();
        $role_type_list = Const_Flow::role_list();
        unset($role_type_list[Const_Flow::ROLE_STAFF]);//去掉普通员工角色
        unset($role_type_list[Const_Flow::ROLE_SUPERIOR]);//去掉主管角色
        //构造所有已有角色
        foreach($role_type_list as $role_index => $role_row){
            if(!empty($role_type) && $role_type != $role_index){
                continue;
            }
            $role_list["{$city_id}|{$role_index}"]['city_name'] = $city_list[$city_id]['city_name'];
            $role_list["{$city_id}|{$role_index}"]['role_name'] = $role_row;
            $role_list["{$city_id}|{$role_index}"]['role_type'] = $role_index;
        }
        //填空
        $bll_role = new Bll_Flow_Role();
        $result = $bll_role->get_role_list($city_id, $role_type);
        if($result){
            foreach($result as $row){
                $role_list["{$row['city_id']}|{$row['role_type']}"]['lsit'][]    = $row;

            }
        }
        $this->request->set_attribute('params',$params);
        $this->request->set_attribute('data', array('city_list'=>$city_list, 'role_type_list'=>$role_type_list));
        $this->request->set_attribute('role_list', $role_list);
        return "Flow_Role";
    }
}